FROM {{ namespace }}/{{ image_prefix }}openstack-base:{{ tag }}
{% block labels %}
LABEL maintainer="{{ maintainer }}" name="{{ image_name }}" build-date="{{ build_date }}"
{% endblock %}

{% block vitrage_base_header %}{% endblock %}

{% import "macros.j2" as macros with context %}

{{ macros.configure_user(name='vitrage') }}

{% if install_type == 'binary' %}

    {% if base_package_type == 'rpm' %}

        {% set vitrage_base_packages = [
            'openstack-vitrage-common'
        ] %}

{{ macros.install_packages(vitrage_base_packages | customizable("packages")) }} \
    && mkdir -p /var/www/cgi-bin/vitrage \
    && cp -a /usr/lib/python{{ distro_python_version }}/site-packages/vitrage/api/app.wsgi /var/www/cgi-bin/vitrage/ \
    && chown -R vitrage: /var/www/cgi-bin/vitrage

    {% elif base_package_type == 'deb' %}
    {% if base_distro == 'debian' %}

    {% set vitrage_base_packages = [
        'python3-vitrage',
        'vitrage-common'
    ] %}

{{ macros.install_packages(vitrage_base_packages | customizable("packages")) }}

    {% else %}

RUN echo '{{ install_type }} not yet available for {{ base_distro }}' \
    && /bin/false

    {% endif %}
    {% endif %}

{% elif install_type == 'source' %}

    {% if base_package_type == 'rpm' %}

        {% set vitrage_base_packages = [
            'httpd',
            'mod_ssl',
            'python3-ldappool',
            'python3-mod_wsgi'
        ] %}

{{ macros.install_packages(vitrage_base_packages | customizable("packages")) }}
RUN sed -i -r 's,^(Listen 80),#\1,' /etc/httpd/conf/httpd.conf \
    && sed -i -r 's,^(Listen 443),#\1,' /etc/httpd/conf.d/ssl.conf

    {% elif base_package_type == 'deb' %}

        {% set vitrage_base_packages = [
            'apache2',
            'libapache2-mod-wsgi-py3',
            'python3-ldappool'
        ] %}

{{ macros.install_packages(vitrage_base_packages | customizable("packages")) }}
RUN echo > /etc/apache2/ports.conf
{% endif %}

{% set vitrage_base_pip_packages = [
    '/vitrage'
] %}

ADD vitrage-base-archive /vitrage-base-source
RUN ln -s vitrage-base-source/* vitrage \
    && {{ macros.install_pip(vitrage_base_pip_packages | customizable("pip_packages")) }} \
    && mkdir -p /etc/vitrage /var/www/cgi-bin/vitrage \
    && cp -r /vitrage/etc/vitrage/* /etc/vitrage/ \
    && cp /vitrage/vitrage/api/app.wsgi /var/www/cgi-bin/vitrage \
    && chown -R vitrage: /etc/vitrage /var/www/cgi-bin/vitrage

{% endif %}

COPY extend_start.sh /usr/local/bin/kolla_extend_start
RUN touch /usr/local/bin/kolla_vitrage_extend_start \
    && chmod 755 /usr/local/bin/kolla_extend_start /usr/local/bin/kolla_vitrage_extend_start

{% block vitrage_base_footer %}{% endblock %}
